#define BLINKER_BLE
#include <Blinker.h>
#define JOY_1 "JOYKey"

BlinkerJoystick JOY1(JOY_1);

const int directionPin = 19; // 控制旋转方向的引脚
const int pwmPin = 21;       // 控制 PWM 占空比的引脚


void joystick1_callback(uint8_t xAxis, uint8_t yAxis)
{
 //analogWrite(pwmPin,yAxis);
  if(yAxis < 128)
  {
    analogWrite(pwmPin,map(-yAxis,-127,0,0,255));
  }
  else if(yAxis > 128)
  {
    analogWrite(pwmPin,map(yAxis,129,255,0,255));
  }
  else if(yAxis == 128)
  {
    analogWrite(pwmPin,0);
  }
  
}

void setup()
{
   pinMode(directionPin, OUTPUT);
   pinMode(pwmPin, OUTPUT);
   JOY1.attach(joystick1_callback);
   Blinker.begin();
  
  
}

void loop()
{
    Blinker.run();
}